package sync1;

import java.util.concurrent.TimeUnit;

public class sync4 {


    synchronized public void fun1() throws InterruptedException {

        System.out.println(Thread.currentThread().getName()+" exec fun1");
        TimeUnit.SECONDS.sleep(1);
    }

    public static void main(String[] args) throws InterruptedException {
        sync4 s = new sync4();
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                try {
                    s.fun1();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            },"thread "+i).start();
        }
    TimeUnit.SECONDS.sleep(10);
    }

}
